%Lumped Capacitance ahe
% Parameters

Ti = -33;         % Initial temperature of the TES (°C)
T_inf = 36;       % Ambient temperature (°C)
h = 20;           % Convective heat transfer coefficient (W/m^2.K)
A = 0.2477;       % Wetted surface area of the TES (m^2)
rho = 2400;       % Density of the material (kg/m^3)
V = 0.0056613;    % Volume of the TES (m^3)
cp = 840;         % Specific heat capacity of the material (J/kg.K)
k = 1.4;          % Thermal conductivity of the material (W/m.K) [You need to define this based on the material]
tmax = 3600;      % Time in seconds (1hr=3600s, 4 hr=14400s)

% Calculate the characteristic length
L_c = V / A;

% Calculate the Biot number
Bi = h * L_c / k;

% Check if lumped capacitance method is valid
if Bi >= 0.1
    error('Biot Number is too large (Bi = %.3f). Lumped Capacitance method is not valid.', Bi);
else
    disp(['Biot Number: ', num2str(Bi)])
    disp('Lumped capacitance method is valid. Proceeding with the solution...')
end

% Time vector (seconds)
t = linspace(0,tmax, 100);  % Time from 0 to tmax

% Lumped capacitance solution
T_t = T_inf + (Ti - T_inf) * exp(-h * A * t / (rho * V * cp));

% Plot the results
figure;
plot(t, T_t, 'LineWidth', 2);
xlabel('Time (s)');
ylabel('Temperature (°C)');
title('Temperature vs. Time for Lumped Capacitance Method');
grid on;